<?php
$page=$_GET['page']??1;
$pagesize=3;
$limit=($page-1)*$pagesize;
$dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
$sql='select * from novel';
$arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$rowsNumber = count($arr);
$pagecount=ceil($rowsNumber/$pagesize);
$novel_title=$_GET['novel_title']??'';
if($novel_title!='')
{
    $memcached=memcache_connect('127.0.0.1',11211);
    //echo $memcached;die;
    $arr=$memcached->get($novel_title);
    if($arr=='')
    {
        echo "没有缓存";
        $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
        $sql="select * from novel where novel_title like '%$novel_title%' limit $limit,$pagesize";
        $arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
       // $count=count($arr);
       // $pagecount=ceil($count/$pagesize);
        $memcached->set($novel_title,$arr);
    }

}
else{
    echo "有缓存";
    $dbh=new PDO('mysql:host=localhost;dbname=gaofei','root','root');
    $sql="select * from novel where novel_title like '%$novel_title%' limit $limit,$pagesize";
    $arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}

?>
<form method="get">
    <table border="1">
        <tr>
            <td><input type="text" name="novel_title"></td>
            <td><input type="submit" value="搜索"></td>
        </tr>
    </table>
</form>
<table border="1">
    <tr>
        <td>小说编号</td>
        <td>小说网址</td>
        <td>小说标题</td>
        <td>小说简介</td>
        <td>小说类型</td>
        <td>小说作者</td>
        <td>操作</td>
    </tr>
    <?php foreach($arr as $key=>$value) { ?>
        <tr>
            <td><?php echo $value['id']?></td>
            <td><?php echo $value['novel_url']?></td>
            <td><?php echo $value['novel_title']?></td>
            <td><?php echo $value['novel_content']?></td>
            <td><?php echo $value['novel_type']?></td>
            <td><?php echo $value['novel_author']?></td>
            <td>
                <a href="no.php?id=<?php echo $value['id']?>">静态化</a>
                <a href="delete.php?id=<?php echo $value['id']?>">删除</a>
                <a href="update.php?id=<?php echo $value['id']?>">修改</a>
            </td>
        </tr>
    <?php } ?>
</table>
<a href="SHOW.php?page=1">首页</a>
<a href="SHOW.php?page=<?php echo $page-1?>">上一页</a>
<a href="SHOW.php?page=<?php echo $page+1?>">下一页</a>
<a href="SHOW.php?page=<?php echo $pagecount?>">尾页</a>

